///////////////////////////////////////////////////////////////////////////////
//
// Licensed under the MIT License
//
// Copyright (c) 2010 Chris Colinsky
// All Rights Reserved
//
// version	0.5
// http://code.google.com/p/sugarcookie/
// http://code.google.com/p/sugarcookie/wiki/License
//
////////////////////////////////////////////////////////////////////////////////

package sugarcookie.preloaders.flex {
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.ProgressEvent;
	import mx.events.FlexEvent;
	import mx.preloaders.IPreloaderDisplay;
	import mx.preloaders.Preloader;

	public class GenericPreloader extends Sprite implements IPreloaderDisplay {
		private var _preloader:Preloader;
		private var _backgroundAlpha:Number;
		private var _backgroundColor:int;
		private var _backgroundImage:Object;
		private var _backgroundSize:String;
		private var _stageHeight:Number;
		private var _stageWidth:Number;
		
		public function set preloader(value:Sprite):void {
			_preloader = value as Preloader;
			value.addEventListener(ProgressEvent.PROGRESS, progressEventHandler);
			value.addEventListener(Event.COMPLETE, completeHandler);
			value.addEventListener(FlexEvent.INIT_PROGRESS, initProgressHandler);
			value.addEventListener(FlexEvent.INIT_COMPLETE, initCompleteEventHandler);
		}
		
		public function set backgroundAlpha(value:Number):void {
			_backgroundAlpha = value;
		}
		
		public function get backgroundAlpha():Number {
			return _backgroundAlpha;
		}
		
		public function set backgroundColor(value:uint):void {
			_backgroundColor = value;
		}
		
		public function get backgroundColor():uint {
			return _backgroundColor;
		}
		
		public function set backgroundImage(value:Object):void {
			_backgroundImage = value;
		}
		
		public function get backgroundImage():Object {
			return _backgroundImage;
		}
		
		public function set backgroundSize(value:String):void {
			_backgroundSize = value;
		}
		
		public function get backgroundSize():String {
			return _backgroundSize;
		}
		
		public function set stageWidth(value:Number):void {
			_stageWidth = value;
		}
		
		public function get stageWidth():Number {
			return _stageWidth;
		}
		
		public function set stageHeight(value:Number):void {
			_stageHeight = value;
		}
		
		public function get stageHeight():Number {
			return _stageHeight;
		}
		
		public function GenericPreloader() {
			super();
		}
		
		public function initialize():void {
			
		}
		
		protected function progressEventHandler(event:ProgressEvent):void {
			trace("[InvisablePreloader] progressEventHandler - percent: "+String(Math.round((event.bytesLoaded/event.bytesTotal)*100)));
		}
		
		protected function initCompleteEventHandler(event:FlexEvent):void {
			trace("[InvisablePreloader] initCompleteEventHandler");
			dispatchEvent(new Event(Event.COMPLETE));
		}
		
		protected function completeHandler(event:Event):void {
			trace("[InvisablePreloader] completeHandler");
		}
		
		protected function initProgressHandler(event:Event):void {
			//trace("[InvisablePreloader] initProgressHandler");
		}
	}
}






